class CommentsController < ApplicationController
  #before_filter :check_request_type, :only => [:create]
  before_filter :get_article, :set_signed_user, :only => [:create]
  
  def create
    @comment = @article.with_options(new_comment_defaults) do |art|
      art.add_comment(params[:comment].symbolize_keys)
    end
    
    if @comment.save!
      flash[:notice] = 'Comment was successful created.'
    end
    
    redirect_to :controller => 'articles', :action => 'show', :id => @article
    
  end
  
  def get_article
    @article = Article.find(params[:id])
  end
  private
  
  def new_comment_defaults
    return { :content => '',
                :user => @signed_user,
                :article => @article,
                :published_at => Time.now,
           }
  end
end
